package xyz.ddlnt.servicemg.controller;

import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.model.dto.TechnologyDTO;
import xyz.ddlnt.model.vo.TechnologyInfoVO;
import xyz.ddlnt.model.vo.TechnologySelectVO;
import xyz.ddlnt.model.vo.TechnologyVO;
import xyz.ddlnt.servicemg.service.TechnologyService;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/1 20:55
 */
@Slf4j
@RequestMapping("/technology")
@RestController
@RequiredArgsConstructor
public class TechnologyController {
    @Resource
    private TechnologyService technologyService;

    /**
     * 查询所有类别科目的基本信息
     * @return
     */
    @GetMapping("/selectTechCategoryInfos")
    public Result<List<TechnologySelectVO>> selectTechCategoryInfos() {
        List<TechnologySelectVO> technologySelectVOS = technologyService.selectTechCategoryInfos();
        return Result.success(technologySelectVOS);
    }

    /**
     * 查询所有科目信息
     * @return
     */
    @GetMapping("/selectAll")
    public Result<List<TechnologyVO>> selectAll() {
        List<TechnologyVO> technologyVOList = technologyService.selectAll();
        return Result.success(technologyVOList);
    }

    /**
     * 根据类别id查询类别下所有科目信息
     * @param categoryId
     * @return
     */
    @GetMapping("/selectByCategoryId")
    public Result<List<TechnologyInfoVO>> selectByCategoryId(@RequestParam Long categoryId) {
        List<TechnologyInfoVO> technologyVOList = technologyService.selectByCategoryId(categoryId);
        return Result.success(technologyVOList);
    }
    /**
     * 根据科目id查询科目信息
     * @param technologyId
     * @return
     */
    @GetMapping("/selectByTechnologyId")
    public Result<TechnologyInfoVO> selectByTechnologyId(@RequestParam Long technologyId) {
        TechnologyInfoVO technologyVO = technologyService.selectByTechnologyId(technologyId);
        return Result.success(technologyVO);
    }

    /**
     * 添加科目信息
     * @param technologyDTO
     * @return
     */
    @PostMapping("/add")
    public Result<TechnologyVO> addTechnology(@RequestBody TechnologyDTO technologyDTO) {
        TechnologyVO technologyAddVO = technologyService.addTechnology(technologyDTO);
        return Result.success(technologyAddVO);
    }

    /**
     * 修改科目信息
     * @param technologyDTO
     * @return
     */
    @PutMapping("/update")
    public Result<LocalDateTime> updateTechnology(@RequestBody TechnologyDTO technologyDTO) {
        LocalDateTime localDateTime = technologyService.updateTechnology(technologyDTO);
        return Result.success(localDateTime);
    }

    /**
     * 删除科目信息
     * @param technologyId
     * @return
     */
    @DeleteMapping("/delete")
    public Result<Boolean> deleteTechnology(@RequestParam Long technologyId) {
        Boolean isDeleted = technologyService.deleteTechnology(technologyId);
        return Result.success(isDeleted);
    }
}
